/** WPI CS509 cisco Stratego MsgGetUserAccount
 * 
 */
package edu.wpi.cs509.messages.server;

import edu.wpi.cs509.messages.MsgBc;
import edu.wpi.cs509.messages.client.MsgLoginReply;
import edu.wpi.cs509.representation.UserPair;

/**
 * This message class handles logging a user in. An acknowledge 
 * message is returned indicating good/bad login.
 * 
 * @author sparadis
 *
 */
public class MsgUserLogin extends MsgServerContext {

	/**
	 * serializable version number
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * pair: the login username/password
	 */
	UserPair pair;
	
	/**
	 * Constructor
	 * @param login pair (username and password).
	 */
	public MsgUserLogin(UserPair pair) {
		this.pair = pair;
	}

	/**
	 * Perform a login.
	 * @return MsgBc - reply msg with login results.
	 */
	@Override
	public MsgBc doExecuteAndGetReply() {
		getConnection().setUser(pair.getUsername());
		//Perform a  login, return results in the reply msg.
		return (new MsgLoginReply(getServer().login(pair)));
	}
	
	/**
	 * Return a string with the message contents. 
	 */
	public String toString() {
		return ("message contents: " + pair);
	}

}

